using System.Collections;
using UnityEngine;

public class OnChargeMine : OnChargeExplosionAdhesive
{
	public float responseRadius;

	public static bool needBlow = true;

	private bool isStandbyMode;

	private bool isExplosion;

	public override void OnCollisionEnter(Collision collision)
	{
		base.OnCollisionEnter(collision);
		objCollider.enabled = true;
		objCollider.isTrigger = true;
		if (objCollider is SphereCollider)
		{
			(objCollider as SphereCollider).radius = responseRadius;
		}
		TrailRenderer component = GetComponent<TrailRenderer>();
		if (component != null)
		{
			component.enabled = false;
		}
	}

	public override void Start()
	{
		base.Start();
		needBlow = true;
		if (base.isMine)
		{
			GameController.instance.playerScript.AddDetonatorMineToList(this);
		}
	}

	protected override void OnDestroy()
	{
		if (needBlow)
		{
			base.OnDestroy();
		}
		if (base.isMine)
		{
			GameController.instance.playerScript.RemoveExplosionMine(this);
		}
	}

	public override IEnumerator Explosion()
	{
		objCollider.enabled = false;
		yield return null;
		objCollider.enabled = true;
		if (objCollider is SphereCollider)
		{
			(objCollider as SphereCollider).radius = explosionRadius;
		}
		isExplosion = true;
		yield return new WaitForSeconds(0.1f);
		PhotonNetwork.Destroy(base.gameObject);
	}

	public override void OnTriggerEnter(Collider other)
	{
		if (!objCollider.isTrigger)
		{
			return;
		}
		if (!isExplosion)
		{
			Mortal componentInParent = other.gameObject.GetComponentInParent<Mortal>();
			if (componentInParent == null)
			{
				return;
			}
			if (TDMController.isTeamGameType && base.photonView.isMine)
			{
				if (componentInParent is EntityBehavior)
				{
					EntityBehavior entityBehavior = componentInParent as EntityBehavior;
					PlayerBehavior playerBehavior = entityBehavior.getMainHuman() as PlayerBehavior;
					PlayerBehavior playerBehavior2 = GameController.instance.FindPlayer(entityBehavior.photonView.ownerId);
					if ((entityBehavior.getMainHuman() != null && playerBehavior != null && playerBehavior.localTeam == TDMController.myTeam && !entityBehavior.isMine) || (entityBehavior.privateCar && playerBehavior2 != null && playerBehavior2.localTeam == TDMController.myTeam))
					{
						return;
					}
				}
				else if (componentInParent is PlayerBehavior)
				{
					PlayerBehavior playerBehavior3 = componentInParent as PlayerBehavior;
					if (playerBehavior3.localTeam == TDMController.myTeam && !playerBehavior3.isMine)
					{
						return;
					}
				}
			}
			if (settings.offlineMode)
			{
				if (componentInParent != GameController.instance.playerScript && (!GameController.instance.playerScript.inCar || componentInParent != GameController.instance.carScript))
				{
					isExplosion = true;
					StartCoroutine(Explosion());
				}
			}
			else if (componentInParent.ownerViewId != -1)
			{
				isExplosion = true;
				StartCoroutine(Explosion());
			}
		}
		else
		{
			base.OnTriggerEnter(other);
		}
	}
}
